import Vue from 'vue'
import Router from 'vue-router'
import Login from "../views/Login.vue"
import Main from "../views/Main.vue"

Vue.use(Router)

let router = new Router({
  routes: [{
      path: "/",
      redirect: "/login"
    },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/main",
      component: Main
    },
  ]
})

router.beforeEach((to,from,next)=>{
  if(to.path==="/login"){
    next()
  }else{
    let ken =window.sessionStorage.getItem("token")
    if(!ken){
      next("/login")
    }else{
      next()
    }
  }
})

export default router
